/*    */ package tools;
/*    */ 
/*    */ import javax.crypto.Cipher;
/*    */ import javax.crypto.spec.SecretKeySpec;
/*    */ 
/*    */ public class AESUtils
/*    */ {
/*    */   private static byte[] Operation(byte[] src, String key, int mode) throws Exception {
/*  9 */     if (key == null) {
/* 10 */       System.out.println("Key不能为空");
/* 11 */       return null;
/*    */     } 
/* 13 */     if (key.length() != 16) {
/* 14 */       System.out.println("Key需要16位长度");
/* 15 */       return null;
/*    */     } 
/*    */     
/* 18 */     byte[] raw = key.getBytes("utf-8");
/* 19 */     SecretKeySpec keySpec = new SecretKeySpec(raw, "AES");
/* 20 */     Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
/* 21 */     cipher.init(mode, keySpec);
/* 22 */     byte[] encrypted = cipher.doFinal(src);
/* 23 */     return encrypted;
/*    */   }
/*    */   
/*    */   public static byte[] Encrypt(byte[] src, String key) throws Exception {
/* 27 */     return Operation(src, key, 1);
/*    */   }
/*    */   
/*    */   public static byte[] Decrypt(byte[] src, String key) throws Exception {
/* 31 */     return Operation(src, key, 2);
/*    */   }
/*    */ }


/* Location:              C:\PGX\Server.jar!\tools\AESUtils.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */